package com.moonce.api.model.vo;

import com.moonce.api.model.User;
import com.moonce.api.util.CommonUtils;
import com.moonce.api.util.constant.Code;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author 马路遥(229010812 @ qq.com)
 * @version V1.0
 * @Title: springmvc-demo
 * @Package com.moonce.api.model.vo
 * @Description: 自定义User返回样式
 * @Date 2017-12-14 11:30
 */
public class UserVO {
    private Integer id;

    private String username;

    private String password;

    private String sex;

    private String email;

    private String name;

    private String createDate;

    private String modifyDate;

    public UserVO() {

    }
    public UserVO(User user) {
        this.id = user.getId();
        this.username = CommonUtils.getStr(user.getUsername());
        this.password = CommonUtils.getStr(user.getPassword());
        if(user.getSex()==1){
            this.sex = "男";
        }else if(user.getSex()==2){
            this.sex = "女";
        }else{
            this.sex = "未知";
        }
        this.email = CommonUtils.getStr(user.getEmail());
        this.name = CommonUtils.getStr(user.getName());
        this.createDate = CommonUtils.dateCastToString(user.getCreateDate(), Code.YYYY_MM_DD_HH_MM_SS);
        this.modifyDate = CommonUtils.dateCastToString(user.getModifyDate(), Code.YYYY_MM_DD_HH_MM_SS);
    }

    /**
     * @Description: 转化user列表为userVO列表方法
     * @param users
     * @return
     * @throws Exception
     * @author 马路遥(229010812@qq.com)
     * @Date 2017/12/14 12:34
     */
    public static List<UserVO> getList(List<User> users){
        List<UserVO> userVOS = new ArrayList<>();
        if(users.size()>0){
            for(User user:users){
                UserVO userVO = new UserVO(user);
                userVOS.add(userVO);
            }
        }
        return userVOS;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreateDate() {
        return createDate;
    }

    public void setCreateDate(String createDate) {
        this.createDate = createDate;
    }

    public String getModifyDate() {
        return modifyDate;
    }

    public void setModifyDate(String modifyDate) {
        this.modifyDate = modifyDate;
    }
}
